<!doctype html>














<!-- `site.alt_lang` can specify a language different from the UI -->
<html lang="en" 
  
>
  <!-- The Head -->

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="theme-color" media="(prefers-color-scheme: light)" content="#f7f7f7">
  <meta name="theme-color" media="(prefers-color-scheme: dark)" content="#1b1b1e">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta
    name="viewport"
    content="width=device-width, user-scalable=no initial-scale=1, shrink-to-fit=no, viewport-fit=cover"
  >

  

  

  
    <!-- Begin Jekyll SEO tag v2.8.0 -->
<meta name="generator" content="Jekyll v4.3.2" />
<meta property="og:title" content="user space slab memory allocator - libumem" />
<meta name="author" content="Chunsheng Luo" />
<meta property="og:locale" content="en" />
<meta name="description" content="对应github： https://github.com/luochenglcs/libumem" />
<meta property="og:description" content="对应github： https://github.com/luochenglcs/libumem" />
<link rel="canonical" href="https://luochenglcs.github.io/posts/sunos-libumem/" />
<meta property="og:url" content="https://luochenglcs.github.io/posts/sunos-libumem/" />
<meta property="og:site_name" content="Cheng Luo" />
<meta property="og:type" content="article" />
<meta property="article:published_time" content="2021-02-03T00:00:00+00:00" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="user space slab memory allocator - libumem" />
<meta name="twitter:site" content="@luochenglcs" />
<meta name="twitter:creator" content="@Chunsheng Luo" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"BlogPosting","author":{"@type":"Person","name":"Chunsheng Luo","url":"https://github.com/luochenglcs"},"dateModified":"2023-08-03T12:13:29+00:00","datePublished":"2021-02-03T00:00:00+00:00","description":"对应github： https://github.com/luochenglcs/libumem","headline":"user space slab memory allocator - libumem","mainEntityOfPage":{"@type":"WebPage","@id":"https://luochenglcs.github.io/posts/sunos-libumem/"},"url":"https://luochenglcs.github.io/posts/sunos-libumem/"}</script>
<!-- End Jekyll SEO tag -->

  

  <title>user space slab memory allocator - libumem | Cheng Luo
  </title>

  <!--
  The Favicons for Web, Android, Microsoft, and iOS (iPhone and iPad) Apps
  Generated by: https://realfavicongenerator.net/
-->



<link rel="apple-touch-icon" sizes="180x180" href="/assets/img/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/img/favicons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/img/favicons/favicon-16x16.png">
<link rel="manifest" href="/assets/img/favicons/site.webmanifest">
<link rel="shortcut icon" href="/assets/img/favicons/favicon.ico">
<meta name="apple-mobile-web-app-title" content="Cheng Luo">
<meta name="application-name" content="Cheng Luo">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-config" content="/assets/img/favicons/browserconfig.xml">
<meta name="theme-color" content="#ffffff">


  
    
      <link rel="preconnect" href="https://fonts.googleapis.com" >
      <link rel="dns-prefetch" href="https://fonts.googleapis.com" >
    
      <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
      <link rel="dns-prefetch" href="https://fonts.gstatic.com" crossorigin>
    
      <link rel="preconnect" href="https://fonts.googleapis.com" >
      <link rel="dns-prefetch" href="https://fonts.googleapis.com" >
    
      <link rel="preconnect" href="https://cdn.jsdelivr.net" >
      <link rel="dns-prefetch" href="https://cdn.jsdelivr.net" >
    

    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Lato&family=Source+Sans+Pro:wght@400;600;700;900&display=swap">
  

  <!-- GA -->
  

  <!-- Bootstrap -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">

  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.4.0/css/all.min.css">

  <link rel="stylesheet" href="/assets/css/style.css">

  
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tocbot@4.21.0/dist/tocbot.min.css">
  

  
    <!-- Manific Popup -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/magnific-popup.min.css">
  

  <!-- JavaScript -->

  
    <!-- Switch the mode between dark and light. -->

<script type="text/javascript">
  class ModeToggle {
    static get MODE_KEY() {
      return 'mode';
    }
    static get MODE_ATTR() {
      return 'data-mode';
    }
    static get DARK_MODE() {
      return 'dark';
    }
    static get LIGHT_MODE() {
      return 'light';
    }
    static get ID() {
      return 'mode-toggle';
    }

    constructor() {
      if (this.hasMode) {
        if (this.isDarkMode) {
          if (!this.isSysDarkPrefer) {
            this.setDark();
          }
        } else {
          if (this.isSysDarkPrefer) {
            this.setLight();
          }
        }
      }

      let self = this;

      /* always follow the system prefers */
      this.sysDarkPrefers.addEventListener('change', () => {
        if (self.hasMode) {
          if (self.isDarkMode) {
            if (!self.isSysDarkPrefer) {
              self.setDark();
            }
          } else {
            if (self.isSysDarkPrefer) {
              self.setLight();
            }
          }

          self.clearMode();
        }

        self.notify();
      });
    } /* constructor() */

    get sysDarkPrefers() {
      return window.matchMedia('(prefers-color-scheme: dark)');
    }

    get isSysDarkPrefer() {
      return this.sysDarkPrefers.matches;
    }

    get isDarkMode() {
      return this.mode === ModeToggle.DARK_MODE;
    }

    get isLightMode() {
      return this.mode === ModeToggle.LIGHT_MODE;
    }

    get hasMode() {
      return this.mode != null;
    }

    get mode() {
      return sessionStorage.getItem(ModeToggle.MODE_KEY);
    }

    /* get the current mode on screen */
    get modeStatus() {
      if (this.isDarkMode || (!this.hasMode && this.isSysDarkPrefer)) {
        return ModeToggle.DARK_MODE;
      } else {
        return ModeToggle.LIGHT_MODE;
      }
    }

    setDark() {
      document.documentElement.setAttribute(ModeToggle.MODE_ATTR, ModeToggle.DARK_MODE);
      sessionStorage.setItem(ModeToggle.MODE_KEY, ModeToggle.DARK_MODE);
    }

    setLight() {
      document.documentElement.setAttribute(ModeToggle.MODE_ATTR, ModeToggle.LIGHT_MODE);
      sessionStorage.setItem(ModeToggle.MODE_KEY, ModeToggle.LIGHT_MODE);
    }

    clearMode() {
      document.documentElement.removeAttribute(ModeToggle.MODE_ATTR);
      sessionStorage.removeItem(ModeToggle.MODE_KEY);
    }

    /* Notify another plugins that the theme mode has changed */
    notify() {
      window.postMessage(
        {
          direction: ModeToggle.ID,
          message: this.modeStatus
        },
        '*'
      );
    }

    flipMode() {
      if (this.hasMode) {
        if (this.isSysDarkPrefer) {
          if (this.isLightMode) {
            this.clearMode();
          } else {
            this.setLight();
          }
        } else {
          if (this.isDarkMode) {
            this.clearMode();
          } else {
            this.setDark();
          }
        }
      } else {
        if (this.isSysDarkPrefer) {
          this.setLight();
        } else {
          this.setDark();
        }
      }

      this.notify();
    } /* flipMode() */
  } /* ModeToggle */

  const modeToggle = new ModeToggle();
</script>

  

  <!-- A placeholder to allow defining custom metadata -->

</head>


  <body>
    <!-- The Side Bar -->

<div id="sidebar" class="d-flex flex-column align-items-end">
  <div class="profile-wrapper">
    <a href="/" id="avatar" class="rounded-circle">
      
        
        <img src="/assets/img/favicons/android-chrome-512x512.png" width="112" height="112" alt="avatar" onerror="this.style.display='none'">
      
    </a>

    <div class="site-title">
      <a href="/">Cheng Luo</a>
    </div>
    <div class="site-subtitle fst-italic">Linux operating system engineer</div>
  </div>
  <!-- .profile-wrapper -->

  <ul class="nav flex-column flex-grow-1 w-100 ps-0">
    <!-- home -->
    <li class="nav-item">
      <a href="/" class="nav-link">
        <i class="fa-fw fas fa-home"></i>
        <span>HOME</span>
      </a>
    </li>
    <!-- the real tabs -->
    
      <li class="nav-item">
        <a href="/categories/" class="nav-link">
          <i class="fa-fw fas fa-stream"></i>
          

          <span>CATEGORIES</span>
        </a>
      </li>
      <!-- .nav-item -->
    
      <li class="nav-item">
        <a href="/tags/" class="nav-link">
          <i class="fa-fw fas fa-tags"></i>
          

          <span>TAGS</span>
        </a>
      </li>
      <!-- .nav-item -->
    
      <li class="nav-item">
        <a href="/archives/" class="nav-link">
          <i class="fa-fw fas fa-archive"></i>
          

          <span>ARCHIVES</span>
        </a>
      </li>
      <!-- .nav-item -->
    
      <li class="nav-item">
        <a href="/about/" class="nav-link">
          <i class="fa-fw fas fa-info-circle"></i>
          

          <span>ABOUT</span>
        </a>
      </li>
      <!-- .nav-item -->
    
  </ul>
  <!-- ul.nav.flex-column -->

  <div class="sidebar-bottom d-flex flex-wrap  align-items-center w-100">
    
      <button class="mode-toggle btn" aria-label="Switch Mode">
        <i class="fas fa-adjust"></i>
      </button>

      
        <span class="icon-border"></span>
      
    

    
      

      
        <a
          href="https://github.com/luochenglcs"
          aria-label="github"
          

          
            target="_blank"
            
          

          

          
            rel="noopener noreferrer"
          
        >
          <i class="fab fa-github"></i>
        </a>
      
    
      

      
    
      

      
        <a
          href="javascript:location.href = 'mailto:' + ['luochunsheng','ustc.edu'].join('@')"
          aria-label="email"
          

          

          

          
        >
          <i class="fas fa-envelope"></i>
        </a>
      
    
  </div>
  <!-- .sidebar-bottom -->
</div>
<!-- #sidebar -->


    <div id="main-wrapper" class="d-flex justify-content-center">
      <div id="main" class="container px-xxl-5">
        <!-- The Top Bar -->

<div id="topbar-wrapper">
  <div
    id="topbar"
    class="container d-flex align-items-center justify-content-between h-100"
  >
    <span id="breadcrumb">
      

      
        
          
            <span>
              <a href="/">
                Home
              </a>
            </span>

          
        
          
        
          
            
              <span>user space slab memory allocator - libumem</span>
            

          
        
      
    </span>
    <!-- endof #breadcrumb -->

    <i id="sidebar-trigger" class="fas fa-bars fa-fw"></i>

    <div id="topbar-title">
      Post
    </div>

    <i id="search-trigger" class="fas fa-search fa-fw"></i>
    <span id="search-wrapper" class="align-items-center">
      <i class="fas fa-search fa-fw"></i>
      <input
        class="form-control"
        id="search-input"
        type="search"
        aria-label="search"
        autocomplete="off"
        placeholder="Search..."
      >
    </span>
    <span id="search-cancel">Cancel</span>
  </div>
</div>

        











<div class="row">
  <!-- core -->
  <div id="core-wrapper" class="col-12 col-lg-11 col-xl-9 pe-xl-4">
    

    <div class="post px-1 px-md-2">
      

      
        
      
        <!-- Refactor the HTML structure -->



<!--
  In order to allow a wide table to scroll horizontally,
  we suround the markdown table with `<div class="table-wrapper">` and `</div>`
-->



<!--
  Fixed kramdown code highlight rendering:
  https://github.com/penibelst/jekyll-compress-html/issues/101
  https://github.com/penibelst/jekyll-compress-html/issues/71#issuecomment-188144901
-->



<!-- Change the icon of checkbox -->


<!-- images -->



  
  

  <!-- CDN URL -->
  

  <!-- Add image path -->
  

  
    
      
      
    

    
    

    

    
    

    
    
    
    

    
      

      
      
      

      
    
      

      
      
      

      
    

    <!-- take out classes -->
    

    

    

    

    <!-- lazy-load images <https://github.com/aFarkas/lazysizes#readme> -->
    
    

    <!-- add image placeholder -->
    
      
    

    <!-- Bypass the HTML-proofer test -->
    

    
      <!-- make sure the `<img>` is wrapped by `<a>` -->
      

      
        <!-- create the image wrapper -->
        
      
    

    <!-- combine -->
    

  

  



<!-- Add header for code snippets -->



<!-- Create heading anchors -->





  
  

  

  
  

  
    
    

    
      
        
        
      

      
      

      
      
      

      

    
      

      
      

      
      
      

      

    
      

      
      

      
      
      

      

    

    

  

  
  

  
    
    

    
      
        
        
      

      
      

      
      
      

      

    

    

  

  
  

  




<!-- return -->




<h1 data-toc-skip>user space slab memory allocator - libumem</h1>

<div class="post-meta text-muted">
    <!-- published date -->
    <span>
      Posted
      <!--
  Date format snippet
  See: ${JS_ROOT}/utils/locale-dateime.js
-->





<em
  class=""
  data-ts="1612310400"
  data-df="ll"
  
    data-bs-toggle="tooltip" data-bs-placement="bottom"
  
>
  Feb  3, 2021
</em>

    </span>

    <!-- lastmod date -->
    
    <span>
      Updated
      <!--
  Date format snippet
  See: ${JS_ROOT}/utils/locale-dateime.js
-->





<em
  class=""
  data-ts="1691064809"
  data-df="ll"
  
    data-bs-toggle="tooltip" data-bs-placement="bottom"
  
>
  Aug  3, 2023
</em>

    </span>
    

  

  <div class="d-flex justify-content-between">
    <!-- author(s) -->
    <span>
      

      By

      <em>
      
        
          <a href="https://github.com/luochenglcs">Chunsheng Luo</a>
          
        
      
      </em>
    </span>

    <div>
      <!-- read time -->
      <!-- Calculate the post's reading time, and display the word count in tooltip -->



<!-- words per minute -->










<!-- return element -->
<span
  class="readtime"
  data-bs-toggle="tooltip"
  data-bs-placement="bottom"
  title="1157 words"
>
  <em>6 min</em> read</span>

    </div>

  </div> <!-- .d-flex -->

</div> <!-- .post-meta -->
<div class="post-content">
  <p>对应github：
https://github.com/luochenglcs/libumem</p>

<div class="language-plaintext highlighter-rouge"><div class="code-header">
        <span data-label-text="Plaintext"><i class="fas fa-code fa-fw small"></i></span>
      <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div><div class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
</pre></td><td class="rouge-code"><pre>reference:
https://arrowpig1979.wordpress.com/2008/08/16/%e4%bd%bf%e7%94%a8libumem%e5%ae%9a%e4%bd%8dmemory-leak%e5%92%8cmemory-corruption%ef%bc%884%ef%bc%89/

https://www.codenong.com/8287649/
</pre></td></tr></tbody></table></code></div></div>

<h3 id="一libumem介绍"><span class="me-2">一、libumem介绍</span><a href="#一libumem介绍" class="anchor text-muted"><i class="fas fa-hashtag"></i></a></h3>

<p>libumem是一个运行在用户模式的内存分配程序库，包含在Solaris 9及以后的版本中。libumem不仅能够优化程序的内存分配，而且还提供了内存分配调试和记录的功能，配合mdb工具，可以轻松观察程序内存的分配情况和定位内存泄漏的问题。</p>

<p>libumem使用Slab概念。Slab是Slab Allocator中一个基本内存单元，代表一个或者多个虚拟内存中的页（Page），通常会被分割成为多个大小等同的Chunks，即Buffer。Buffer含有用户所使用的数据，以及一些额外的信息（取决于环境变量的设置）。这些额外的信息对我们调试，检测内存泄漏非常有用。下面就是 Buffer 的一个基本结构：</p>

<p><a href="/posts/./images/sunos-libumem/libumem的原理.png" class="popup img-link "><img data-src="/posts/./images/sunos-libumem/libumem的原理.png" alt="image-20201110171811756" class="lazyload" data-proofer-ignore></a></p>

<div class="language-c highlighter-rouge"><div class="code-header">
        <span data-label-text="C"><i class="fas fa-code fa-fw small"></i></span>
      <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div><div class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
</pre></td><td class="rouge-code"><pre><span class="n">Metadata</span> <span class="n">Section</span><span class="err">，提供内存分配的长度信息，在</span><span class="mi">32</span><span class="err">位程序应用中为</span><span class="mi">8</span><span class="err">个字节。</span>
<span class="n">User</span> <span class="n">Data</span> <span class="n">Section</span><span class="err">，用户使用的内存区域，存储用户数据。</span>
<span class="n">Redzone</span> <span class="n">Section</span><span class="err">，</span><span class="mi">8</span><span class="err">个字节，隔离</span><span class="n">User</span> <span class="n">Data</span><span class="err">和</span><span class="n">Debug</span> <span class="n">Meta</span> <span class="n">Data</span><span class="err">。</span>
<span class="n">Debug</span> <span class="n">Metadata</span><span class="err">，</span><span class="mi">8</span><span class="err">个字节。前面四个字节为指针，指向一个</span><span class="n">umem_bufctl_audit</span><span class="err">结构，记录内存分配时候的堆栈。此结构的定义可以在</span><span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">include</span><span class="o">/</span><span class="n">umem_impl</span><span class="p">.</span><span class="n">h</span><span class="err">找到。后面的四个字节为校验位，与前面字节一起来判断这个</span><span class="n">buffer</span><span class="err">是否被破坏。</span>
</pre></td></tr></tbody></table></code></div></div>

<p>https://hosam.wordpress.com/opensolaris-open-source-from-sun-microsystems-inc/</p>

<h3 id="二libumem的维测特性"><span class="me-2">二、libumem的维测特性</span><a href="#二libumem的维测特性" class="anchor text-muted"><i class="fas fa-hashtag"></i></a></h3>

<h4 id="1-linux目前的内存调测手段"><span class="me-2">1 linux目前的内存调测手段</span><a href="#1-linux目前的内存调测手段" class="anchor text-muted"><i class="fas fa-hashtag"></i></a></h4>

<div class="language-plaintext highlighter-rouge"><div class="code-header">
        <span data-label-text="Plaintext"><i class="fas fa-code fa-fw small"></i></span>
      <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div><div class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
</pre></td><td class="rouge-code"><pre>1.glibc内存检测
2.valgrind内存检查机制
3、gperftools内存检查机制
4、ASan内存检查机制
5、Memwatch内存检查机制
6、Dr.Memory内存检查机制
9、Electric Fence内存检查机制
8、Dmalloc内存检查机制
</pre></td></tr></tbody></table></code></div></div>

<h3 id="2-libumem的内存调测"><span class="me-2">2 libumem的内存调测</span><a href="#2-libumem的内存调测" class="anchor text-muted"><i class="fas fa-hashtag"></i></a></h3>

<p>需要和mdb工具配合，</p>

<p>我们先看下面的例子：</p>

<div class="language-c highlighter-rouge"><div class="code-header">
        <span data-label-text="C"><i class="fas fa-code fa-fw small"></i></span>
      <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div><div class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="rouge-code"><pre><span class="cp">#include</span> <span class="cpf">&lt;stdlib.h&gt;</span><span class="cp">
#include</span> <span class="cpf">&lt;stdio.h&gt;</span><span class="cp">
#include</span> <span class="cpf">&lt;unistd.h&gt;</span><span class="cp">
</span>
<span class="kt">void</span> <span class="nf">test_leak_malloc</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
        <span class="kt">char</span> <span class="o">*</span><span class="n">p</span> <span class="o">=</span> <span class="n">malloc</span><span class="p">(</span><span class="mi">50</span><span class="p">);</span>
        <span class="n">p</span> <span class="o">=</span> <span class="n">malloc</span><span class="p">(</span><span class="mi">100</span><span class="p">);</span>
        <span class="n">free</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">test_UAF</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
        <span class="kt">char</span> <span class="o">*</span><span class="n">p</span> <span class="o">=</span> <span class="n">malloc</span><span class="p">(</span><span class="mi">50</span><span class="p">);</span>
        <span class="n">free</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
        <span class="o">*</span><span class="n">p</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">void</span> <span class="nf">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
        <span class="kt">char</span> <span class="o">*</span><span class="n">p</span> <span class="o">=</span> <span class="n">malloc</span><span class="p">(</span><span class="mi">50</span><span class="p">);</span>
        <span class="n">test_leak_malloc</span><span class="p">();</span>
        <span class="n">test_UAF</span><span class="p">();</span>
        <span class="n">pause</span><span class="p">();</span>
        <span class="k">return</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">gcc</span> <span class="o">-</span><span class="n">g</span> <span class="n">test</span><span class="p">.</span><span class="n">c</span> <span class="o">-</span><span class="n">o</span> <span class="n">test</span>
<span class="n">UMEM_DEBUG</span><span class="o">=</span><span class="k">default</span><span class="p">,</span> <span class="n">UMEM_LOGGING</span><span class="o">=</span><span class="n">transaction</span> <span class="n">LD_PRELOAD</span><span class="o">=/</span><span class="n">usr</span><span class="o">/</span><span class="n">local</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span> <span class="p">.</span><span class="o">/</span><span class="n">test</span><span class="o">&amp;</span>
<span class="c1">//使用 man umem_debug查看UMEM_DEBUG、UMEM_LOGGING的含义。</span>
</pre></td></tr></tbody></table></code></div></div>

<div class="language-c highlighter-rouge"><div class="code-header">
        <span data-label-text="C"><i class="fas fa-code fa-fw small"></i></span>
      <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div><div class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="rouge-code"><pre><span class="p">[</span><span class="n">root</span><span class="err">@</span><span class="n">localhost</span> <span class="o">~</span><span class="p">]</span><span class="err">#</span> <span class="n">mdb</span> <span class="o">-</span><span class="n">p</span> <span class="err">`</span><span class="n">pidof</span> <span class="n">test</span><span class="err">`</span> <span class="c1">//使用mdb attach到test进程</span>
<span class="n">loading</span> <span class="n">modules</span><span class="o">:</span> <span class="p">[</span> <span class="n">libgcc_s</span><span class="o">-</span><span class="mi">8</span><span class="o">-</span><span class="mi">20191121</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">1</span> <span class="n">libdl</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span> <span class="n">libpthread</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span> <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span> <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span> <span class="n">ld</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span> <span class="p">]</span>
<span class="o">::</span><span class="n">findleaks</span> <span class="o">-</span><span class="n">d</span>
<span class="n">BYTES</span>             <span class="n">LEAKED</span>         <span class="n">VMEM_SEG</span> <span class="n">CALLER</span>
<span class="mi">16384</span>                  <span class="mi">6</span>     <span class="mi">7</span><span class="n">f3daf3af000</span> <span class="n">MMAP</span>
<span class="mi">4096</span>                   <span class="mi">1</span>     <span class="mi">7</span><span class="n">f3db1c40000</span> <span class="n">MMAP</span>
<span class="mi">8192</span>                   <span class="mi">1</span>     <span class="mi">7</span><span class="n">f3db1c3c000</span> <span class="n">MMAP</span>
<span class="mi">8192</span>                   <span class="mi">1</span>     <span class="mi">7</span><span class="n">f3db1c28000</span> <span class="n">MMAP</span>
<span class="mi">33595392</span>               <span class="mi">1</span>     <span class="mi">7</span><span class="n">f3dafa0c000</span> <span class="n">MMAP</span>
<span class="mi">16384</span>                  <span class="mi">1</span>     <span class="mi">7</span><span class="n">f3daf771000</span> <span class="n">MMAP</span>
<span class="o">------------------------------------------------------------------------</span>
           <span class="n">Total</span>       <span class="mi">6</span> <span class="n">oversized</span> <span class="n">leaks</span><span class="p">,</span> <span class="mi">33648640</span> <span class="n">bytes</span>

<span class="n">CACHE</span>             <span class="n">LEAKED</span>           <span class="n">BUFCTL</span> <span class="n">CALLER</span>
<span class="mo">00007</span><span class="n">f3db1bba048</span>       <span class="mi">1</span> <span class="mo">00007</span><span class="n">f3db1b3e7e0</span> <span class="n">main</span><span class="o">+</span><span class="mh">0x12</span>  <span class="c1">//内存泄漏1</span>
<span class="mo">00007</span><span class="n">f3db1bba048</span>       <span class="mi">1</span> <span class="mo">00007</span><span class="n">f3db1b3e8c0</span> <span class="n">test_leak_malloc</span><span class="o">+</span><span class="mh">0x12</span>  <span class="c1">//内存泄漏2</span>
<span class="o">------------------------------------------------------------------------</span>
           <span class="n">Total</span>       <span class="mi">2</span> <span class="n">buffers</span><span class="p">,</span> <span class="mi">160</span> <span class="n">bytes</span>

<span class="n">mmap</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="n">leak</span><span class="o">:</span> <span class="p">[</span><span class="mi">7</span><span class="n">f3daf3af000</span><span class="p">,</span> <span class="mi">7</span><span class="n">f3daf3b3000</span><span class="p">),</span> <span class="mi">16384</span> <span class="n">bytes</span>
<span class="n">mmap</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="n">leak</span><span class="o">:</span> <span class="p">[</span><span class="mi">7</span><span class="n">f3db1c40000</span><span class="p">,</span> <span class="mi">7</span><span class="n">f3db1c41000</span><span class="p">),</span> <span class="mi">4096</span> <span class="n">bytes</span>
<span class="n">mmap</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="n">leak</span><span class="o">:</span> <span class="p">[</span><span class="mi">7</span><span class="n">f3db1c3c000</span><span class="p">,</span> <span class="mi">7</span><span class="n">f3db1c3e000</span><span class="p">),</span> <span class="mi">8192</span> <span class="n">bytes</span>
<span class="n">mmap</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="n">leak</span><span class="o">:</span> <span class="p">[</span><span class="mi">7</span><span class="n">f3db1c28000</span><span class="p">,</span> <span class="mi">7</span><span class="n">f3db1c2a000</span><span class="p">),</span> <span class="mi">8192</span> <span class="n">bytes</span>
<span class="n">mmap</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="n">leak</span><span class="o">:</span> <span class="p">[</span><span class="mi">7</span><span class="n">f3dafa0c000</span><span class="p">,</span> <span class="mi">7</span><span class="n">f3db1a16000</span><span class="p">),</span> <span class="mi">33595392</span> <span class="n">bytes</span>
<span class="n">mmap</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="n">leak</span><span class="o">:</span> <span class="p">[</span><span class="mi">7</span><span class="n">f3daf771000</span><span class="p">,</span> <span class="mi">7</span><span class="n">f3daf775000</span><span class="p">),</span> <span class="mi">16384</span> <span class="n">bytes</span>
<span class="n">umem_alloc_80</span> <span class="n">leak</span><span class="o">:</span> <span class="mi">1</span> <span class="n">buffer</span><span class="p">,</span> <span class="mi">80</span> <span class="n">bytes</span>
            <span class="n">ADDR</span>          <span class="n">BUFADDR</span>        <span class="n">TIMESTAMP</span>           <span class="n">THREAD</span>
                            <span class="n">CACHE</span>          <span class="n">LASTLOG</span>         <span class="n">CONTENTS</span>
    <span class="mi">7</span><span class="n">f3db1b3e7e0</span>     <span class="mi">7</span><span class="n">f3db1b6bf60</span> <span class="mi">60116209000</span><span class="n">b4637</span>      <span class="o">-</span><span class="mi">1312650368</span>
                     <span class="mi">7</span><span class="n">f3db1bba048</span>     <span class="mi">7</span><span class="n">f3db1bf8300</span>                <span class="mi">0</span>
                 <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">umem_alloc</span><span class="o">+</span><span class="mh">0x98</span>
                 <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">malloc</span><span class="o">+</span><span class="mh">0x39</span> <span class="c1">//泄漏内存的申请流程</span>
                 <span class="n">main</span><span class="o">+</span><span class="mh">0x12</span>
                 <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span><span class="err">`</span><span class="n">__libc_start_main</span><span class="o">+</span><span class="mh">0xf3</span>
                 <span class="n">_start</span><span class="o">+</span><span class="mh">0x2e</span>

<span class="n">umem_alloc_80</span> <span class="n">leak</span><span class="o">:</span> <span class="mi">1</span> <span class="n">buffer</span><span class="p">,</span> <span class="mi">80</span> <span class="n">bytes</span>
            <span class="n">ADDR</span>          <span class="n">BUFADDR</span>        <span class="n">TIMESTAMP</span>           <span class="n">THREAD</span>
                            <span class="n">CACHE</span>          <span class="n">LASTLOG</span>         <span class="n">CONTENTS</span>
    <span class="mi">7</span><span class="n">f3db1b3e8c0</span>     <span class="mi">7</span><span class="n">f3db1b6bef0</span> <span class="mi">60116209000</span><span class="n">b463c</span>      <span class="o">-</span><span class="mi">1312650368</span>
                     <span class="mi">7</span><span class="n">f3db1bba048</span>     <span class="mi">7</span><span class="n">f3db1bf83c0</span>                <span class="mi">0</span>
                 <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">umem_alloc</span><span class="o">+</span><span class="mh">0x98</span>
                 <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">malloc</span><span class="o">+</span><span class="mh">0x39</span>
                 <span class="n">test_leak_malloc</span><span class="o">+</span><span class="mh">0x12</span> <span class="c1">//泄漏内存的申请流程</span>
                 <span class="n">main</span><span class="o">+</span><span class="mh">0x1b</span>
                 <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span><span class="err">`</span><span class="n">__libc_start_main</span><span class="o">+</span><span class="mh">0xf3</span>
                 <span class="n">_start</span><span class="o">+</span><span class="mh">0x2e</span>
</pre></td></tr></tbody></table></code></div></div>

<p>通过findleaks -d可以查看到内存泄漏的调用栈和信息；</p>

<div class="language-c highlighter-rouge"><div class="code-header">
        <span data-label-text="C"><i class="fas fa-code fa-fw small"></i></span>
      <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div><div class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="rouge-code"><pre><span class="n">T</span><span class="o">-</span><span class="mi">0</span><span class="p">.</span><span class="mo">000000000</span>  <span class="n">addr</span><span class="o">=</span><span class="mi">7</span><span class="n">f3db1b6be80</span>  <span class="n">umem_alloc_80</span> <span class="c1">//test_UAF free addr=7f3db1b6be80</span>
         <span class="n">test_UAF</span><span class="o">+</span><span class="mh">0x22</span>
         <span class="n">main</span><span class="o">+</span><span class="mh">0x20</span>
         <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span><span class="err">`</span><span class="n">__libc_start_main</span><span class="o">+</span><span class="mh">0xf3</span>
         <span class="n">_start</span><span class="o">+</span><span class="mh">0x2e</span>

<span class="n">T</span><span class="o">-</span><span class="mi">0</span><span class="p">.</span><span class="mo">000000005</span>  <span class="n">addr</span><span class="o">=</span><span class="mi">7</span><span class="n">f3db1b6be80</span>  <span class="n">umem_alloc_80</span> <span class="c1">//test_UAF malloc(50) addr=7f3db1b6be80 </span>
         <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">umem_alloc</span><span class="o">+</span><span class="mh">0x98</span>
         <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">malloc</span><span class="o">+</span><span class="mh">0x39</span>
         <span class="n">test_UAF</span><span class="o">+</span><span class="mh">0x12</span>
         <span class="n">main</span><span class="o">+</span><span class="mh">0x20</span>
         <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span><span class="err">`</span><span class="n">__libc_start_main</span><span class="o">+</span><span class="mh">0xf3</span>
         <span class="n">_start</span><span class="o">+</span><span class="mh">0x2e</span>

<span class="n">T</span><span class="o">-</span><span class="mi">0</span><span class="p">.</span><span class="mo">000000060</span>  <span class="n">addr</span><span class="o">=</span><span class="mi">7</span><span class="n">f3db1b6af40</span>  <span class="n">umem_alloc_128</span> <span class="c1">//test_leak_malloc free addr=7f3db1b6af40</span>
         <span class="n">test_leak_malloc</span><span class="o">+</span><span class="mh">0x30</span>
         <span class="n">main</span><span class="o">+</span><span class="mh">0x1b</span>
         <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span><span class="err">`</span><span class="n">__libc_start_main</span><span class="o">+</span><span class="mh">0xf3</span>
         <span class="n">_start</span><span class="o">+</span><span class="mh">0x2e</span>

<span class="n">T</span><span class="o">-</span><span class="mi">0</span><span class="p">.</span><span class="mo">000000067</span>  <span class="n">addr</span><span class="o">=</span><span class="mi">7</span><span class="n">f3db1b6af40</span>  <span class="n">umem_alloc_128</span> <span class="c1">//test_leak_malloc malloc(100) addr=7f3db1b6af40</span>
         <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">umem_alloc</span><span class="o">+</span><span class="mh">0x98</span>
         <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">malloc</span><span class="o">+</span><span class="mh">0x39</span>
         <span class="n">test_leak_malloc</span><span class="o">+</span><span class="mh">0x20</span>
         <span class="n">main</span><span class="o">+</span><span class="mh">0x1b</span>
         <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span><span class="err">`</span><span class="n">__libc_start_main</span><span class="o">+</span><span class="mh">0xf3</span>
         <span class="n">_start</span><span class="o">+</span><span class="mh">0x2e</span>
             
<span class="n">T</span><span class="o">-</span><span class="mi">0</span><span class="p">.</span><span class="mo">0000001</span><span class="mi">82</span>  <span class="n">addr</span><span class="o">=</span><span class="mi">7</span><span class="n">f3db1b6bef0</span>  <span class="n">umem_alloc_80</span> <span class="c1">//test_leak_malloc malloc(50) addr=7f3db1b6bef0</span>
         <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">umem_alloc</span><span class="o">+</span><span class="mh">0x98</span>
         <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">malloc</span><span class="o">+</span><span class="mh">0x39</span> 
         <span class="n">test_leak_malloc</span><span class="o">+</span><span class="mh">0x12</span>        
         <span class="n">main</span><span class="o">+</span><span class="mh">0x1b</span>                    
         <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span><span class="err">`</span><span class="n">__libc_start_main</span><span class="o">+</span><span class="mh">0xf3</span>
         <span class="n">_start</span><span class="o">+</span><span class="mh">0x2e</span>                  
                                      
<span class="n">T</span><span class="o">-</span><span class="mi">0</span><span class="p">.</span><span class="mo">0000001</span><span class="mi">87</span>  <span class="n">addr</span><span class="o">=</span><span class="mi">7</span><span class="n">f3db1b6bf60</span>  <span class="n">umem_alloc_80</span> <span class="c1">//main malloc(50) addr=7f3db1b6bf60</span>
         <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">umem_alloc</span><span class="o">+</span><span class="mh">0x98</span>
         <span class="n">libumem</span><span class="p">.</span><span class="n">so</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="p">.</span><span class="mi">0</span><span class="err">`</span><span class="n">malloc</span><span class="o">+</span><span class="mh">0x39</span> 
         <span class="n">main</span><span class="o">+</span><span class="mh">0x12</span>                    
         <span class="n">libc</span><span class="o">-</span><span class="mi">2</span><span class="p">.</span><span class="mi">28</span><span class="p">.</span><span class="n">so</span><span class="err">`</span><span class="n">__libc_start_main</span><span class="o">+</span><span class="mh">0xf3</span>
         <span class="n">_start</span><span class="o">+</span><span class="mh">0x2e</span>                  
</pre></td></tr></tbody></table></code></div></div>

<p>通过umalog命令可以看到具体分配的细节；</p>

<p>从上面也可以看到有两处申请未释放。</p>

<p>memory corruption的处理；通过memory corruption的有user after free, double free, array bound write…</p>

<div class="language-plaintext highlighter-rouge"><div class="code-header">
        <span data-label-text="Plaintext"><i class="fas fa-code fa-fw small"></i></span>
      <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div><div class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
</pre></td><td class="rouge-code"><pre>::umem_verify
Cache Name                      Addr             Cache Integrity     
...
umem_alloc_80                       7f3db1bba048 1 corrupt buffer
umem_alloc_96                       7f3db1bb9048 clean
...
</pre></td></tr></tbody></table></code></div></div>

<pre><code class="language-C">7f3db1bba048::umem_verify
Summary for cache 'umem_alloc_80'
  buffer 7f3db1b6be80 (free) seems corrupted, at 7f3db1b6be90 //这里已经free的7f3db1b6be80地址出现corrupted
</code></pre>

<p>通过上面umalog命令可以查看到申请的调用栈：</p>

<div class="language-plaintext highlighter-rouge"><div class="code-header">
        <span data-label-text="Plaintext"><i class="fas fa-code fa-fw small"></i></span>
      <button aria-label="copy" data-title-succeed="Copied!"><i class="far fa-clipboard"></i></button></div><div class="highlight"><code><table class="rouge-table"><tbody><tr><td class="rouge-gutter gl"><pre class="lineno">1
2
3
4
5
6
7
</pre></td><td class="rouge-code"><pre>T-0.000000005  addr=7f3db1b6be80  umem_alloc_80 //test_UAF malloc(50) addr=7f3db1b6be80 
         libumem.so.0.0.0`umem_alloc+0x98
         libumem.so.0.0.0`malloc+0x39
         test_UAF+0x12
         main+0x20
         libc-2.28.so`__libc_start_main+0xf3
         _start+0x2e
</pre></td></tr></tbody></table></code></div></div>

<p>综合信息可以知道test_UAF中出现use after free的情况；</p>

<font color="red">ps：目前libumem支持调用栈的getstack的代码还没有合入； 后面需要合入</font>

<p>社区代码还有很多待完善的地方。</p>

</div>

<div class="post-tail-wrapper text-muted">

  <!-- categories -->
  
  <div class="post-meta mb-3">
    <i class="far fa-folder-open fa-fw me-1"></i>
    
      <a href='/categories/package/'>Package</a>,
      <a href='/categories/libumem/'>libumem</a>
  </div>
  
  <!-- post.html -->

  <!-- tags -->
  
  <div class="post-tags">
    <i class="fa fa-tags fa-fw me-1"></i>
      
      <a href="/tags/libumem/"
          class="post-tag no-text-decoration" >libumem</a>
      
  </div>
  
  
  <div class="post-tail-bottom
    d-flex justify-content-between align-items-center mt-3 pt-5 pb-2">
    <div class="license-wrapper">

      

        

        This post is licensed under 
        <a href="https://creativecommons.org/licenses/by/4.0/">
          CC BY 4.0
        </a>
         by the author.

      
    </div>

    <!-- Post sharing snippet -->

<div class="share-wrapper">
  <span class="share-label text-muted me-1">Share</span>
  <span class="share-icons">
    
    
    

    
      
      <a
        href="https://twitter.com/intent/tweet?text=user%20space%20slab%20memory%20allocator%20-%20libumem%20-%20Cheng%20Luo&url=https%3A%2F%2Fluochenglcs.github.io%2Fposts%2Fsunos-libumem%2F"
        data-bs-toggle="tooltip"
        data-bs-placement="top"
        title="Twitter"
        target="_blank"
        rel="noopener"
        aria-label="Twitter"
      >
        <i class="fa-fw fab fa-twitter"></i>
      </a>
    
      
      <a
        href="https://www.facebook.com/sharer/sharer.php?title=user%20space%20slab%20memory%20allocator%20-%20libumem%20-%20Cheng%20Luo&u=https%3A%2F%2Fluochenglcs.github.io%2Fposts%2Fsunos-libumem%2F"
        data-bs-toggle="tooltip"
        data-bs-placement="top"
        title="Facebook"
        target="_blank"
        rel="noopener"
        aria-label="Facebook"
      >
        <i class="fa-fw fab fa-facebook-square"></i>
      </a>
    
      
      <a
        href="https://t.me/share/url?url=https%3A%2F%2Fluochenglcs.github.io%2Fposts%2Fsunos-libumem%2F&text=user%20space%20slab%20memory%20allocator%20-%20libumem%20-%20Cheng%20Luo"
        data-bs-toggle="tooltip"
        data-bs-placement="top"
        title="Telegram"
        target="_blank"
        rel="noopener"
        aria-label="Telegram"
      >
        <i class="fa-fw fab fa-telegram"></i>
      </a>
    

    <i
      id="copy-link"
      class="fa-fw fas fa-link small"
      data-bs-toggle="tooltip"
      data-bs-placement="top"
      title="Copy link"
      data-title-succeed="Link copied successfully!"
    >
    </i>
  </span>
</div>


  </div><!-- .post-tail-bottom -->

</div><!-- div.post-tail-wrapper -->


      
    
      
    </div>
  </div>
  <!-- #core-wrapper -->

  <!-- panel -->
  <div id="panel-wrapper" class="col-xl-3 ps-2 text-muted">
    <div class="access">
      <!-- Get the last 5 posts from lastmod list. -->














  <div id="access-lastmod" class="post">
    <div class="panel-heading">Recently Updated</div>
    <ul class="post-content list-unstyled ps-0 pb-1 ms-1 mt-2">
      
        
        
        
        <li class="text-truncate lh-lg">
          <a href="/posts/%E5%86%85%E5%AD%98%E6%95%B0%E6%8D%AE%E5%BA%93/">MMDB (memory database)</a>
        </li>
      
        
        
        
        <li class="text-truncate lh-lg">
          <a href="/posts/userspace-rcu%E9%94%81/">userspace rcu lock</a>
        </li>
      
        
        
        
        <li class="text-truncate lh-lg">
          <a href="/posts/Real-time-operating-system/">Realtime Operating System</a>
        </li>
      
        
        
        
        <li class="text-truncate lh-lg">
          <a href="/posts/HUNDSUN-LightOS/">Hundsun Lightos</a>
        </li>
      
        
        
        
        <li class="text-truncate lh-lg">
          <a href="/posts/linux-struct-folio/">struct folio</a>
        </li>
      
    </ul>
  </div>
  <!-- #access-lastmod -->


      <!-- The trending tags list -->















  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
      
        
        

  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
      
        
        

  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
      
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        



  <div id="access-tags">
    <div class="panel-heading">Trending Tags</div>
    <div class="d-flex flex-wrap mt-3 mb-1 me-3">
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/lock/">lock</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/libumem/">libumem</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/mm/">mm</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/autonuma/">autonuma</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/bfs/">BFS</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/bus/">Bus</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/caladan/">caladan</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/damon/">damon</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/deep-learning/">Deep Learning</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/dma/">DMA</a>
      
    </div>
  </div>


    </div>

    
      
      



  <div id="toc-wrapper" class="ps-0 pe-4 mb-5">
    <div class="panel-heading ps-3 pt-2 mb-2">Contents</div>
    <nav id="toc"><ul><li>user space slab memory allocator - libumem<ul><li><a href="#一libumem介绍">一、libumem介绍</a></li><li><a href="#二libumem的维测特性">二、libumem的维测特性</a><ul><li><a href="#1-linux目前的内存调测手段">1 linux目前的内存调测手段</a></li></ul></li><li><a href="#2-libumem的内存调测">2 libumem的内存调测</a></li></ul></li></ul></li></ul></nav>
  </div>
  


    
  </div>
</div>

<!-- tail -->

  <div class="row">
    <div id="tail-wrapper" class="col-12 col-lg-11 col-xl-9 px-3 pe-xl-4 mt-5">
      
        
        <!--
  Recommend the other 3 posts according to the tags and categories of the current post,
  if the number is not enough, use the other latest posts to supplement.
-->

<!-- The total size of related posts -->


<!-- An random integer that bigger than 0 -->


<!-- Equals to TAG_SCORE / {max_categories_hierarchy} -->








  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  
    
  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  

  






<!-- Fill with the other newlest posts -->





  <div id="related-posts" class="mb-2 mb-sm-4">
    <h3 class="pt-2 mb-4 ms-1" data-toc-skip>
      Further Reading
    </h3>
    <div class="row row-cols-1 row-cols-md-2 row-cols-xl-3 g-4 mb-4">
      
        
        
        <div class="col">
          <a href="/posts/libumem-Introduce/" class="card post-preview h-100">
            <div class="card-body">
              <!--
  Date format snippet
  See: ${JS_ROOT}/utils/locale-dateime.js
-->





<em
  class="small"
  data-ts="1616284800"
  data-df="ll"
  
>
  Mar 21, 2021
</em>

              <h4 class="pt-0 my-2" data-toc-skip>libumem Introduce</h4>
              <div class="text-muted small">
                <p>
                  





                  一款你值得拥有的内存问题定位神器

一 背景介绍



​      使用C语言开发时，对于内存资源的申请和释放时非常常见的场景，但这也给广大程序带来了很多困扰，一旦出现如越界访问，重复释放，use after free，内存泄露等问题时，定位起来非常麻烦。

​	因为这个原因，现有的大部分内存管理框架或多或少的都会提供一些内存调测能力，协助定位问题。但是目前用起来不是太难使用，就是约束限制...
                </p>
              </div>
            </div>
          </a>
        </div>
      
        
        
        <div class="col">
          <a href="/posts/numad-start-failed/" class="card post-preview h-100">
            <div class="card-body">
              <!--
  Date format snippet
  See: ${JS_ROOT}/utils/locale-dateime.js
-->





<em
  class="small"
  data-ts="1600323000"
  data-df="ll"
  
>
  Sep 17, 2020
</em>

              <h4 class="pt-0 my-2" data-toc-skip>numad systemctl start failed</h4>
              <div class="text-muted small">
                <p>
                  





                  1 systemct start failed
1、R9 x86环境systemctl启动失败

● numad.service - numad - The NUMA daemon that manages application locality.
   Loaded: loaded (/usr/lib/systemd/system/numad.service; disabled; ven...
                </p>
              </div>
            </div>
          </a>
        </div>
      
        
        
        <div class="col">
          <a href="/posts/sunos-mdb/" class="card post-preview h-100">
            <div class="card-body">
              <!--
  Date format snippet
  See: ${JS_ROOT}/utils/locale-dateime.js
-->





<em
  class="small"
  data-ts="1603152000"
  data-df="ll"
  
>
  Oct 20, 2020
</em>

              <h4 class="pt-0 my-2" data-toc-skip>Modular Debugger (MDB)</h4>
              <div class="text-muted small">
                <p>
                  





                  适用于linux系统的mdb：
https://github.com/luochenglcs/mdb

If the code is useful to you - great !. Spread it around and get people to use, debug and enhance it.

一、libumem_ready赋值

umem_update_variables
 ...
                </p>
              </div>
            </div>
          </a>
        </div>
      
    </div>
    <!-- .card-deck -->
  </div>
  <!-- #related-posts -->


      
        
        <!-- Navigation buttons at the bottom of the post. -->

<div class="post-navigation d-flex justify-content-between">
  
    <a
      href="/posts/linux-SEI/"
      class="btn btn-outline-primary"
      prompt="Older"
    >
      <p>Linux System Error Interrupt</p>
    </a>
  

  
    <a
      href="/posts/Peripherals-Bus-Delivery/"
      class="btn btn-outline-primary"
      prompt="Newer"
    >
      <p>Peripherals Bus Delivery</p>
    </a>
  
</div>

      
        
        <!--  The comments switcher -->


      
    </div>
  </div>


        <!-- The Search results -->

<div id="search-result-wrapper" class="d-flex justify-content-center unloaded">
  <div class="col-11 post-content">
    <div id="search-hints">
      <!-- The trending tags list -->















  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
      
        
        

  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
      
        
        

  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
      
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        

  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
    
  
    
    
    
    
      
        
        



  <div id="access-tags">
    <div class="panel-heading">Trending Tags</div>
    <div class="d-flex flex-wrap mt-3 mb-1 me-3">
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/lock/">lock</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/libumem/">libumem</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/mm/">mm</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/autonuma/">autonuma</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/bfs/">BFS</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/bus/">Bus</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/caladan/">caladan</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/damon/">damon</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/deep-learning/">Deep Learning</a>
      
        
        <a class="post-tag btn btn-outline-primary" href="/tags/dma/">DMA</a>
      
    </div>
  </div>


    </div>
    <div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div>
  </div>
</div>

      </div>
    </div>

    <!-- The Footer -->

<footer>
  <div class="container px-lg-4">
    <div class="d-flex justify-content-center align-items-center text-muted mx-md-3">
      <p>Using the <a href="https://jekyllrb.com" target="_blank" rel="noopener">Jekyll</a> theme <a href="https://github.com/cotes2020/jekyll-theme-chirpy" target="_blank" rel="noopener">Chirpy</a>
      </p>

      <p>©
        2023
        <a href="https://gitee.com/luochenglcs">luochunsheng</a>.
        
          <span
            data-bs-toggle="tooltip"
            data-bs-placement="top"
            title="Except where otherwise noted, the blog posts on this site are licensed under the Creative Commons Attribution 4.0 International (CC BY 4.0) License by the author."
          >Some rights reserved.</span>
        
      </p>
    </div>
  </div>
</footer>


    <div id="mask"></div>

    <button id="back-to-top" aria-label="back-to-top" class="btn btn-lg btn-box-shadow">
      <i class="fas fa-angle-up"></i>
    </button>

    
      <div
        id="notification"
        class="toast"
        role="alert"
        aria-live="assertive"
        aria-atomic="true"
        data-bs-animation="true"
        data-bs-autohide="false"
      >
        <div class="toast-header">
          <button
            type="button"
            class="btn-close ms-auto"
            data-bs-dismiss="toast"
            aria-label="Close"
          ></button>
        </div>
        <div class="toast-body text-center pt-0">
          <p class="px-2 mb-3">A new version of content is available.</p>
          <button type="button" class="btn btn-primary" aria-label="Update">
            Update
          </button>
        </div>
      </div>
    

    <!-- JS selector for site. -->

<!-- commons -->



<!-- layout specified -->


  

  
    <!-- image lazy-loading & popup & clipboard -->
    
  















  
    

    

  

  
    

    

  

  
    

    

  

  
    

    

  

  
    

    

  

  
    

    

  

  
    

    

  

  
    

    

  

  
    

    

  

  
    

    

  

  
    

    

  



  <script src="https://cdn.jsdelivr.net/combine/npm/jquery@3.7.0/dist/jquery.min.js,npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js,npm/simple-jekyll-search@1.10.0/dest/simple-jekyll-search.min.js,npm/lazysizes@5.3.2/lazysizes.min.js,npm/magnific-popup@1.1.0/dist/jquery.magnific-popup.min.js,npm/clipboard@2.0.11/dist/clipboard.min.js,npm/dayjs@1.11.7/dayjs.min.js,npm/dayjs@1.11.7/locale/en.min.js,npm/dayjs@1.11.7/plugin/relativeTime.min.js,npm/dayjs@1.11.7/plugin/localizedFormat.min.js,npm/tocbot@4.21.0/dist/tocbot.min.js"></script>






<script defer src="/assets/js/dist/post.min.js"></script>






    

    <!--
  Jekyll Simple Search loader
  See: <https://github.com/christian-fei/Simple-Jekyll-Search>
-->





<script>
  /* Note: dependent library will be loaded in `js-selector.html` */
  SimpleJekyllSearch({
    searchInput: document.getElementById('search-input'),
    resultsContainer: document.getElementById('search-results'),
    json: '/assets/js/data/search.json',
    searchResultTemplate: '<div class="px-1 px-sm-2 px-lg-4 px-xl-0">  <a href="{url}">{title}</a>  <div class="post-meta d-flex flex-column flex-sm-row text-muted mt-1 mb-1">    {categories}    {tags}  </div>  <p>{snippet}</p></div>',
    noResultsText: '<p class="mt-5"></p>',
    templateMiddleware: function(prop, value, template) {
      if (prop === 'categories') {
        if (value === '') {
          return `${value}`;
        } else {
          return `<div class="me-sm-4"><i class="far fa-folder fa-fw"></i>${value}</div>`;
        }
      }

      if (prop === 'tags') {
        if (value === '') {
          return `${value}`;
        } else {
          return `<div><i class="fa fa-tag fa-fw"></i>${value}</div>`;
        }
      }
    }
  });
</script>

  </body>
</html>

